package cn.tuning.pojo;

import cn.tuning.utils.HttpStatus;
import cn.tuning.utils.ResultCode;

import java.io.Serializable;

/**
 * @author lixiaolong
 * @date 2021-08-06 21:18
 * @description: 响应实体
 */
public class APIResult implements Serializable {
    private static final long serialVersionUID = 1L;

    /**
     * 返回代码
     */
    private Integer code;

    /**
     * 提示消息
     */
    private String msg;

    /**
     * 返回数据
     */
    private Object data;

    public APIResult() {
    }

    public APIResult(String msg, int code)
    {
        this.setMsg(msg);
        this.setCode(code);
    }

    public APIResult(String msg, int code, Object data)
    {
        this.setMsg(msg);
        this.setCode(code);
        this.setData(data);
    }

    public APIResult(Integer code, String msg, Object data)
    {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static APIResult success()
    {
        return new APIResult(ResultCode.SUCCESS.getMsg(), ResultCode.SUCCESS.getCode());
    }

    public static APIResult success(Object data)
    {
        return new APIResult(ResultCode.SUCCESS.getMsg(), ResultCode.SUCCESS.getCode(), data);
    }

    public static APIResult success(String msg, Object data)
    {
        return new APIResult(msg, HttpStatus.SUCCESS, data);
    }

    public static APIResult success(ResultCode resultCode, Object data)
    {
        return new APIResult(resultCode.getMsg(), resultCode.getCode(), data);
    }

    public static APIResult success(ResultCode resultCode)
    {
        return new APIResult(resultCode.getMsg(), resultCode.getCode());
    }

    public static APIResult fail()
    {
        return new APIResult(ResultCode.SERVER_ERROR.getMsg(), ResultCode.SERVER_ERROR.getCode());
    }

    public static APIResult fail(String msg)
    {
        return new APIResult(msg, HttpStatus.ERROR);
    }

    public static APIResult fail(ResultCode resultCode)
    {
        return new APIResult(resultCode.getMsg(), resultCode.getCode());
    }

    public static APIResult fail(ResultCode resultCode, Object data)
    {
        return new APIResult(resultCode.getMsg(), resultCode.getCode(), data);
    }

    /**
     * 邮箱不存在时返回
     */
    public static APIResult errorUsername(){
        return new APIResult(ResultCode.LOGIN_ERROR_USERNAME.getMsg(),ResultCode.LOGIN_ERROR_USERNAME.getCode());
    }
    /**
     *
     */
    public static APIResult massageMiss(){
        return new APIResult(ResultCode.LOGIN_ERROR_MASSAGE.getMsg(),ResultCode.LOGIN_ERROR_MASSAGE.getCode());
    }

    /**
     * 密码错误时返回
     */
    public static APIResult errorPassword(){
        return new APIResult(ResultCode.LOGIN_ERROR.getMsg(),ResultCode.LOGIN_ERROR.getCode());
    }

    /**
     * 注册时邮箱已存在 输入邮箱为空
     * getCode:
     */
    public static APIResult registerFail(){
        return new APIResult(ResultCode.REGISTER_ERROR.getMsg(),ResultCode.REGISTER_ERROR.getCode());
    }

    /**
     * 注册时邮箱密码为空
     * @return 账号注册失败
     */
    public static APIResult errorRegister(){
        return new APIResult(ResultCode.REGISTER_FAIL.getMsg(),ResultCode.REGISTER_FAIL.getCode());
    }

    /**
     * 操作失败
     * @return 操作失败
     */
    public static APIResult errorOperate(){
        return new APIResult(ResultCode.OPERATE_ERROR.getMsg(),ResultCode.OPERATE_ERROR.getCode());
    }

    /**
     * 发送验证码时邮箱为空
     * @return
     */
    public static APIResult nullEmail(){
        return new APIResult(ResultCode.VERIFY_ERROR.getMsg(),ResultCode.VERIFY_ERROR.getCode());
    }

    /**
     * 验证吗错误
     * @return
     */
    public static APIResult errorVerify(){
        return new APIResult(ResultCode.VERIFY_CODE_ERROR.getMsg(),ResultCode.VERIFY_CODE_ERROR.getCode());
    }

    /**
     * 邮箱格式错误
     * @return  400 邮箱格式错误,请输入正确的邮箱
     */
     public static APIResult errorMail(){
         return new APIResult(ResultCode.ERROR_MAIL.getMsg(),ResultCode.ERROR_MAIL.getCode());
     }

    /**
     * 未登录状态
     * @return  400  你尚未登录,请先登录
     */
    public static APIResult notLogin(){
        return new APIResult(ResultCode.NOT_LOGIN.getMsg(),ResultCode.NOT_LOGIN.getCode());
    }

    /**
     * @return  400 输入信息不全
     */
     public static APIResult inputNotFull(){
         return new APIResult(ResultCode.INPUT_NOT_FULL.getMsg(),ResultCode.INPUT_NOT_FULL.getCode());
     }

    /**
     * @return 400 参数缺失
     */
    public static APIResult parameterMiss(){
        return new APIResult(ResultCode.BAD_REQUEST.getMsg(),ResultCode.BAD_REQUEST.getCode());
    }

    /**
     *
     * @return 400 骑手尚未注册,请先注册骑手
     */
    public static APIResult riderISNotFind(){
        return new APIResult(ResultCode.NOT_FOUND_RIDER.getMsg(),ResultCode.NOT_FOUND_RIDER.getCode());
    }


    @Override
    public String toString()
    {
        return "{" + "\"code\":" + code + ", \"msg\":\"" + msg + '\"' + ", \"data\":\"" + data + '\"'  + '}';
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }


    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
}
